package com.skt.common_hr.mompo.model
{
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.wcl.utils.DateUtil;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.collections.ArrayCollection;

	public class MompoApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "MompoApprovalProxy";
		public var dataProvider:ArrayCollection;

		private var _bAppType:Boolean = false;		// 정산 포함여부
		private var _amount:Number;
		
		public var MompoObj:Object;
		
		private var templateHTML1:String = "";
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function MompoApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate1();
		}
		
		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}
		
		public function get title():String 
		{
			var tmp:String;
			tmp = "임신부 등록 신청";	
/* 			tmp = "구성원 포상 (";			
			tmp += MompoObj.AWDDT + ", " + MompoObj.ENAME;  			
			tmp += ")"; */
			return tmp;
		}
		


		public function get content():String
		{
			return buildHTML();
		}
		
		public function get appCode():String 
		{
			return "17"; 	//
		}
 		
 		private function loadTemplate1():void
		{
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest("assets/template/Mompo.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}
 		
		
		private function templateResult(event:Event):void
		{
			templateHTML1 = event.target.data;
		}
		
		

		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}


		private function buildHTML():String
		{
			var htmlAll:String = templateHTML1;
			var htmlBlock:String = "";
			
			var ptnPERNR:RegExp  		= /__PERNR__/; 
			var ptnENAME:RegExp  		= /__ENAME__/;
			var ptnBEGDA:RegExp  		= /__BEGDA__/;
			var ptnENDDA:RegExp  		= /__ENDDA__/;
			var ptnORGTX:RegExp  		= /__ORGTX__/;
			
			

			
			htmlAll = htmlAll.replace(ptnPERNR		, MompoObj.PERNR);
			htmlAll = htmlAll.replace(ptnENAME		, MompoObj.ENAME);
			htmlAll = htmlAll.replace(ptnBEGDA		, MompoObj.BEGDA);
			htmlAll = htmlAll.replace(ptnENDDA		, MompoObj.ENDDA);
			htmlAll = htmlAll.replace(ptnORGTX		, MompoObj.ORGTX);

			return htmlAll;
		}
	}
}